package com.artist.controller;

import com.artist.entity.TbUser;
import com.artist.service.LoginService;
import com.artist.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVisitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Api(tags = "用户登陆")
@Controller
public class loginController {
    @Autowired
    private LoginService loginService;


    @GetMapping("/login")
    public String loginPage(){
        return "login";
    }




    @ApiOperation(value = "用户登陆验证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uname",value = "用户名",required = true,paramType = "form"),
            @ApiImplicitParam(name="upassword",value = "密码",required = true,paramType = "form")})
    @PostMapping("/login")
    @ResponseBody
    public String userLogin(@RequestParam("uname") String uname,@RequestParam("upassword") String upassword){
        TbUser tbUser   = loginService.userLogin(uname,upassword);
        if(tbUser!=null){
            System.out.println("success");
            return "login";
        }else {
            System.out.println("用户名或者密码不正确");
            return "incorrect username or password";
        }
    }
}
